using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Xml.Serialization;

namespace PeDALS.Tools.AZ.PSTArchive.OutputData
{
    [XmlRoot(Namespace = "http://www.pedalspreservation.org")]
    public class Message
    {
        private byte[] mbaOrigMessage;
        private DateTime mdatReceived;
        private List<Attach> mlAttachments;
        private List<NVP> mlRecipients;
        private List<NVP> mlItemDates;
        private List<NVP> mlConversationIDs;
        private long mlngSize;
        private string mstrBody;
        private string mstrBodyType;
        private string mstrDataVersion;
        private string mstrEngineVersion;
        private string mstrHeader;
        private string mstrPlainText;
        private string mstrSubject;

        public Message()
        {
            mstrDataVersion = string.Format("{0} - v. {1} {2}", FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).Comments, FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion, FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion);
        }

        [XmlAttribute(AttributeName = "dataversion")]
        public string DataVersion
        {
            get
            {
                return mstrDataVersion;
            }
            set
            {
            }
        }

        [XmlAttribute(AttributeName = "engineversion")]
        public string EngineVersion
        {
            get
            {
                return mstrEngineVersion;
            }
            set
            {
                mstrEngineVersion = value;
            }
        }

        [XmlElement(typeof(byte[]), ElementName="origmessage")]
        public byte[] OrigMessage
        {
            get
            {
                return mbaOrigMessage;
            }
            set
            {
                mbaOrigMessage = value;
            }
        }

        [XmlElement(typeof(long), ElementName="messagesize")]
        public long Size
        {
            get
            {
                return mlngSize;
            }
            set
            {
                mlngSize = value;
            }
        }

        [XmlArrayAttribute("itemparties")]
        [XmlArrayItem("itemparty")]
        public List<NVP> Recipients
        {
            get
            {
                return mlRecipients;
            }
            set
            {
                mlRecipients = value;
            }
        }

        [XmlArrayAttribute("itemdates")]
        [XmlArrayItem("itemdate")]
        public List<NVP> ItemDates
        {
            get
            {
                return mlItemDates;
            }
            set
            {
                mlItemDates = value;
            }
        }
        
        [XmlElement(typeof(string), ElementName="itemdesc")]
        public string Subject
        {
            get
            {
                return mstrSubject;
            }
            set
            {
                mstrSubject = value;
            }
        }
        
        [XmlElement(typeof(string), ElementName="bodytype")]
        public string BodyType
        {
            get
            {
                return mstrBodyType;
            }
            set
            {
                mstrBodyType = value;
            }
        }

        [XmlElement(typeof(string), ElementName="body")]
        public string Body
        {
            get
            {
                return mstrBody;
            }
            set
            {
                mstrBody = value;
            }
        }

        [XmlElement(typeof(string), ElementName = "plaintext")]
        public string PlainText
        {
            get
            {
                return mstrPlainText;
            }
            set
            {
                mstrPlainText = value;
            }
        }

        [XmlArrayAttribute("otheridentifiers")]
        [XmlArrayItem("otheridentifier")]
        public List<NVP> ConversationIDs
        {
            get
            {
                return mlConversationIDs;
            }
            set
            {
                mlConversationIDs = value;
            }
        }

        [XmlElement(typeof(string), ElementName="header")]
        public string Header
        {
            get
            {
                return mstrHeader;
            }
            set
            {
                mstrHeader = value;
            }
        }

        // Set the element name and namespace of the XML element.
        //[XmlElement(ElementName="Attachment", Namespace="http://www.pedalspreservation.org")]

        [XmlArrayAttribute("Components")]
        [XmlArrayItem("Component")]
        public List<Attach> Attachments
        {
            get
            {
                return mlAttachments;
            }
            set
            {
                mlAttachments = value;
            }
        }

        internal DateTime Received
        {
            get
            {
                return mdatReceived;
            }
            set
            {
                mdatReceived = value;
            }
        }

        internal string Filespec
        {
            get
            {
                return string.Format("email{0:yyyyMMddhhmmsstt}", mdatReceived).ToLower();
            }
        }
    }
}
